package chalmers.game.subterranean.ui.view;

import chalmers.game.subterranean.event.Bus;
import chalmers.game.subterranean.event.events.player.PlayerMoveEvent;
import chalmers.game.subterranean.util.options.Variables;
import chalmers.game.subterranean.util.options.WorldValues;
import com.google.common.eventbus.Subscribe;
import javafx.animation.TranslateTransition;
import javafx.scene.Node;

/**
 * Moves the world and everything in it when the player moves.
 * 
 * @author Alex Evert
 */
public class World {
  private final TranslateTransition mover;

  public World(Node world) {
    mover = new TranslateTransition();
    mover.setNode(world);
    mover.setDuration(Variables.ANIMATION_DURATION);
    Bus.INSTANCE.register(this);
  }

  /**
   * The player is centered in screen, all other object move vertically if the player does in the
   * model.
   * 
   * @param event Event sent when player moved.
   */
  @Subscribe
  public void move(PlayerMoveEvent event) {
    mover.setToY(-(event.point.y * WorldValues.VIEW_TO_MODEL_SCALE + WorldValues.LEVEL_SIZE
        * event.depth)
        + WorldValues.LEVEL_SIZE / 2 - WorldValues.BLOCK_SIZE / 2);
    mover.play();
  }

}
